﻿/// <summary>
/// 等待状态
/// </summary>
public class GameStateWaiting : GameStateBase
{

    public override void Enter()
    {
        DebugInfo.Log("GameStateWaiting.Enter");

        GameDataKernel.inst.state = GameDataKernel.State.STATE_WAITING;
    }

    public override void Leave()
    {
        DebugInfo.Log("GameStateWaiting.Leave");
    }

    /// <summary>
    /// 处理数据包
    /// </summary>
    /// <param name="message"></param>
    /// <returns></returns>
    public override bool ProcessPacket(IOMessage message)
    {
        switch(message.code)
        {
            case IOCmds.SMSG_PLAYER_JOIN_ROOM:
                // 有玩家加入房间
                GameDataKernel.inst.HandleMessage(message);
                return true;

            case IOCmds.SMSG_SET_ROOM_FINISHED:
                // 房间被解散，退回到主界面
                NetIOController.inst.isGame = false;
                NetIOController.inst.ConnectToNewURL(Constants.LOGIN_URL);
                return true;

            case IOCmds.WS_CONN_OPEN:
                // 与服务器的连接打开
                UIRootController.inst.ShowMask(false);

                if (!NetIOController.inst.isGame)
                {
                    // 连接到了游戏服务器
                    GameController.inst.SwitchTo(HomeProcedure.inst);
                }
                return true;

            case IOCmds.SMSG_SET_ROOM_INFO:
                GameDataKernel.inst.HandleMessage(message);
                // 切换到游戏状态
                GameProceduar.inst.Switch(new GameStateGaming());
                return true;

            case IOCmds.WS_CONN_CLOSED:
                // 连接失败或者/连接断开
                UIRootController.inst.ShowMask(true);
                NetIOController.inst.Connect(null);
                return true;

            case IOCmds.SMSG_SET_PLAYER_EXIT_ROOM:
                GameDataKernel.inst.HandleMessage(message);
                return true;
        }
        return base.ProcessPacket(message);
    }
}
